home *** CD-ROM | disk | FTP | other *** search
/ Inter.Net 55-1 / Inter.Net 55-1.iso / CBuilder / Info / TeachU14 / SAMS / Code / Day13 / smtptstu.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-02-08  |  3.1 KB  |  89 lines

  1. //---------------------------------------------------------------------------
  2. #include <vcl\vcl.h>
  3. #pragma hdrstop
  4.  
  5. #include "SMTPTstU.h"
  6. //---------------------------------------------------------------------------
  7. #pragma package(smart_init)
  8. #pragma resource "*.dfm"
  9. TMainForm *MainForm;
  10. //---------------------------------------------------------------------------
  11. __fastcall TMainForm::TMainForm(TComponent* Owner)
  12.     : TForm(Owner)
  13. {
  14. }
  15. //---------------------------------------------------------------------------
  16. //
  17. // NOTE: You mail have to specifically set the name of your
  18. // mail server for the Host property. In some cases just
  19. // "mail" works. In other cases you have to specify the
  20. // exact mail server name. If your SMTP server is a secure
  21. // server then you may have to set the UserID property to
  22. // your user name as well.
  23. //
  24. void __fastcall TMainForm::ConnectBtnClick(TObject *Sender)
  25. {
  26.   SMTP->Host = "mail";
  27.   SMTP->Connect();
  28. }
  29. //---------------------------------------------------------------------------
  30.  
  31. void __fastcall TMainForm::SMTPSuccess(TObject *Sender)
  32. {
  33.   StatusBar->SimpleText = "Mail Sent!";
  34.   SMTP->Disconnect();
  35.   DisconnectBtn->Enabled = false;
  36.   SendBtn->Enabled = false;
  37.   ConnectBtn->Enabled = true;
  38. }
  39. //---------------------------------------------------------------------------
  40. void __fastcall TMainForm::SMTPFailure(TObject *Sender)
  41. {
  42.   StatusBar->SimpleText = "Mail Failure";
  43.   SMTP->Disconnect();
  44. }
  45. //---------------------------------------------------------------------------
  46.  
  47. void __fastcall TMainForm::SendBtnClick(TObject *Sender)
  48. {
  49.   SMTP->PostMessage->FromAddress = FromEdit->Text;
  50.   SMTP->PostMessage->ToAddress->Add(ToEdit->Text);
  51.   SMTP->PostMessage->Subject = SubjectEdit->Text;
  52.   SMTP->PostMessage->Body->Assign(Message->Lines);
  53.   SMTP->SendMail();
  54. }
  55. //---------------------------------------------------------------------------
  56. void __fastcall TMainForm::DisconnectBtnClick(TObject *Sender)
  57. {
  58.   StatusBar->SimpleText = "Not Connected";
  59.   SMTP->Disconnect();
  60. }
  61. //---------------------------------------------------------------------------
  62. void __fastcall TMainForm::SMTPConnect(TObject *Sender)
  63. {
  64.   StatusBar->SimpleText = "Connected";
  65.   DisconnectBtn->Enabled = true;
  66.   SendBtn->Enabled = true;
  67.   ConnectBtn->Enabled = false;
  68.   // It would make sense to send the mail when connected to the SMTP
  69.   // server. Unfortunately that wasn't working at the time this program
  70.   // was written. As a workaround you could post a user-defined message
  71.   // to yourself from here and send the e-mail messsage in the handler
  72.   // for the user-defined message.
  73. }
  74. //---------------------------------------------------------------------------
  75.  
  76. void __fastcall TMainForm::SMTPDisconnect(TObject *Sender)
  77. {
  78.   // As of this writing this event is fired even after the object has
  79.   // been destroyed. The following line prevents an Access Violation
  80.   // if that happens.
  81.   if (!SendBtn) return;
  82.  
  83.   DisconnectBtn->Enabled = false;
  84.   SendBtn->Enabled = false;
  85.   ConnectBtn->Enabled = true;
  86. }
  87. //---------------------------------------------------------------------------
  88.  
  89.